﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Thrift.Protocol;
using Thrift.Transport;

namespace WpfAppThrift
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            HelloWorldClient.Say();
        }
    }

    public static class HelloWorldClient
    {
        public static void Say(int port=7911, string ip = "47.100.197.222")//string ip = "47.100.197.222"  string ip = "localhost")
        {
            TTransport transport = new TSocket(ip, port,2000);
            TProtocol protocol = new TCompactProtocol(transport);
            Hello.Client client = new Hello.Client(protocol);
            
            try
            {
                transport.Open();
                Console.WriteLine("helloBoolean：" + client.helloBoolean(false));

                Console.WriteLine("helloInt：" + client.helloInt(007));
                Console.WriteLine("helloNull：" + client.helloNull());
                Console.WriteLine("helloString：" + client.helloString("hi qc"));
                client.helloVoid();
            }
            catch (Thrift.TApplicationException x)
            {
                Console.WriteLine(x.StackTrace);

            }
            finally
            {
                transport.Close();
            }
        }
    }

}
